package com.chaodroid.athena;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chaodroid.commen.activity.BasaActivity;
import com.chaodroid.commen.utils.Utils;
import com.chaodriod.common.utils.screen.ScreenUtils;
import com.chaodroid.flyui.widget.navigation.BottomNavigation;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BasaActivity {

    List<String> list = new ArrayList();
    int[] mageResIDs = {R.drawable.home_banner_a, R.drawable.home_banner_b, R.drawable.home_banner_c};

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Utils.init(this.getApplicationContext());
        setContentView(R.layout.activity_main);
//        Window window = getWindow();
//        //取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏
//        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//        //需要设置这个 flag 才能调用 setStatusBarColor 来设置状态栏颜色
//        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//        //设置状态栏颜色
//        window.setStatusBarColor(Color.TRANSPARENT);
        Log.e(getClass().getSimpleName(), "getScreenWidth: " + ScreenUtils.getScreenWidth());
        Log.e(getClass().getSimpleName(), "getScreenHeight: " + ScreenUtils.getScreenHeight());
        Log.e(getClass().getSimpleName(), "getScreenRealWidth: " + ScreenUtils.getScreenRealWidth());
        Log.e(getClass().getSimpleName(), "getScreenRealHeight: " + ScreenUtils.getScreenRealHeight());
        Log.e(getClass().getSimpleName(), "getStatusBarHeight: " + ScreenUtils.getStatusBarHeight());
        Log.e(getClass().getSimpleName(), "getNavigationBarHeight: " + ScreenUtils.getNavigationBarHeight());
        ScreenUtils.setSystemUi(this,true,false,true);
//        ScreenUtils.hideSystemUI(this);
        initView();
        Dialog dialog = new AlertDialog.Builder(this)
                .setMessage("123456")
                .create();
        dialog.show();
    }

    private void initView() {
        list.add("首页");
        list.add("资讯");
        list.add("视频");
        list.add("游戏");
        list.add("我的");
        BottomNavigation bottom = findViewById(R.id.bottom);
        bottom.setAdapter(new BottomAdapter(), null);

//        CustomViewPager banner = findViewById(R.id.banner);
//        banner.setAdapter(new LoopPagerAdapter(new BannerAdapter()));
//
//        final PointIndicator pointIndicator = findViewById(R.id.point);
//        pointIndicator.setAdapter(new PointIndicator.Adapter() {
//            @Override
//            public int getItemCount() {
//                return mageResIDs.length;
//            }
//
//            @Override
//            public int getItemMagin() {
//                return 0;
//            }
//
//            @Override
//            public View bindItemView(int position) {
//                return null;
//            }
//        });
//        pointIndicator.setPosition(0);
//
//        banner.addOnPageChangeListener(new LoopPageChangeListener(mageResIDs.length, new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//            }
//
//            @Override
//            public void onPageSelected(int position) {
//                pointIndicator.setPosition(position);
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int state) {
//            }
//        }));
//
//        banner.setCurrentItem((Integer.MAX_VALUE / 2 - Integer.MAX_VALUE / 2 % mageResIDs.length), false);
    }

    class BannerAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return mageResIDs.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView imageView = new ImageView(MainActivity.this);
            imageView.setImageResource(mageResIDs[position]);
            return imageView;
        }
    }

    class BottomAdapter extends BottomNavigation.Adapter {

        @Override
        public int getItemCount() {
            return list.size();
        }

        @Override
        public View bindItemView(int position) {
            TextView itemView = new TextView(MainActivity.this);
            itemView.setGravity(Gravity.CENTER);
            String s = list.get(position);
            itemView.setText(s);
            return itemView;
        }
    }

    /**
     * 隐藏虚拟按键，并且全屏
     */
    protected void hideBottomUIMenu() {
        //隐藏虚拟按键，并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }

}
